home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5161 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  58 lines

  1. Path: beach.and.nl!usenet
  2. From: jos@and.nl (Jos A. Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What's your compiler's answer?
  5. Date: 7 Feb 1996 17:39:29 GMT
  6. Organization: AND Operations Research B.V.
  7. Message-ID: <4fao4h$dn8@beach.and.nl>
  8. References: <1996Feb7.140945.28351@cs.rit.edu>
  9. NNTP-Posting-Host: klepzeiker.and.nl
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <1996Feb7.140945.28351@cs.rit.edu>, kar@cs.rit.edu wrote:
  15.  
  16. |        In preparing some materials for a course, I wrote the following
  17. |program to illustrate that the order of expression evaluation is not
  18. |determined completely by the precedence of the operators involved.  I
  19. |ran it on every compiler I could find and, not surprisingly, got lots of
  20. |different answers.
  21.  
  22. |        int main(){
  23. |                int i = 10;
  24. |
  25. |                i = i-- - --i * ( i = -3 ) * i++ + ++i;
  26. |                printf( "i = %d\n", i );
  27. |                return 0;
  28. |        }
  29. |
  30. |Results found to date:
  31. |
  32. |21      Borland C/C++ 4.0, Turbo C++ 4.5
  33. |-86     Sun 3/50 cc
  34. |-85     Sun Sparc cc, SunOS 4.1.4 (a K&R compiler)
  35. |4       Sun Sparc acc, SunOS 4.1.4 (an ANSI compiler)
  36. |36      DEC VAX/VMS
  37. |21      Silicon Graphics Indy, IRIX 5.3
  38. |-63     gcc 2.6.3
  39.  
  40. Here are some more results:
  41.  
  42.  "biff"     gcc 2.4.1 (after sunset)
  43.  1/0     xlc AIX 4 (after typing it all in single-handed on the 2nd SP/2 node)
  44.  NaN     xlc AIX 4 (running the same thingy again ..)
  45.  
  46. No seriously, you shouldn't present this example at all, because the
  47. behavior of that expression is undefined. One single object 'i' is
  48. altered more than once between two sequence points, so anything can
  49. happen. And this 'anything' doesn't happen because of a lack of 
  50. complete determination of operator precedence ...
  51.  
  52. kind regards,
  53.  
  54. Jos aka jos@and.nl
  55. -- 
  56. Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
  57.  
  58.